<%@page import="com.tubeonfire.entity.Advertising"%>
<%@page import="com.google.appengine.api.blobstore.BlobKey"%>
<%@page import="com.google.appengine.api.images.ImagesServiceFactory"%>
<%@page import="com.google.appengine.api.images.ImagesService"%>
<%@page import="java.util.TreeMap"%>
<%@page import="com.google.appengine.api.blobstore.BlobstoreServiceFactory"%>
<%@page import="com.google.appengine.api.blobstore.BlobstoreService"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
	ImagesService imagesService = ImagesServiceFactory.getImagesService(); 		
	Advertising obj = (Advertising)session.getAttribute("obj");	
	BlobKey blobKey = new BlobKey(obj.getContent());
	TreeMap check = (TreeMap)session.getAttribute("check");
	session.removeAttribute("check");
	if(check==null){
		check = new TreeMap();
	}
%>
<jsp:include page="/admin/elements/header.jsp">
	<jsp:param value="Advertising Form" name="title"/>
</jsp:include>
<script type="text/javascript" src="/admin/js/mine/admin.js"></script>
<script type="text/javascript" src="/admin/js/mine/form_advertising.js"></script>
	<body class="loggedin">
		<jsp:include page="/admin/elements/top.jsp"/>
	    <!-- START OF MAIN CONTENT -->
	    <div class="mainwrapper">
	     	<div class="mainwrapperinner">         	        
				<jsp:include page="/admin/elements/left.jsp">
					<jsp:param value="advertising" name="current_page"/>
				</jsp:include>					              	                   
	        	<div class="maincontent noright">
	        		<div class="maincontentinner">	            	
		                <ul class="maintabmenu">		
		                	<li><a href="/admin/advertising/manage?place=1">Home</a></li>
		                	<li><a href="/admin/advertising/manage?place=2">Detail</a></li>
		                	<li><a href="/admin/advertising/manage?place=3">Newest & Most View</a></li>
		                	<li><a href="/admin/advertising/manage?place=4">Playlist</a></li>
		                	<li><a href="/admin/advertising/manage?place=5">Channel</a></li>
		                	<li><a href="/admin/advertising/manage?place=6">Search & Tag</a></li>
		                	<li><a href="/admin/advertising/manage?place=7">All Playlist</a></li>
		                	<li><a href="/admin/advertising/manage?place=8">All Channel</a></li>	              	
		                	<li class="current"><a href="/admin/advertising/add">New Ads</a></li>
		                </ul><!--maintabmenu-->	                
	                	<div class="content">	
	                	<jsp:include page="/admin/elements/message.jsp"/>
	                	<div id="messageDiv" class="notification hidden">						   
						    <p></p>
						</div>	   	                    
	                    	<div class="contenttitle">
	                    		<h2 class="image"><span>Fill Advertising Information</span></h2>
	                    	</div>
	                    	<br />
		                    <form class="stdform" enctype="multipart/form-data"  action="<%=blobstoreService.createUploadUrl("/admin/advertising/add") %>" method="post" id="advertisingForm">		                   	     
		                   		<p>
		                        	<label>Advertising Type : </label>
		                            <span class="field">
		                            	<select name="advertisingType" id="advertisingType">
		                            		<option value="1" <%=(obj.getType()==1)?"selected='selected'":""%>>Google Adsense</option>
		                            		<option value="2" <%=(obj.getType()==2)?"selected='selected'":""%>>Your Advertising</option>
		                            	</select>		                            	
		                            </span>		                            		                           
		                        </p>  
		                        <p>
		                        	<label>Place : </label>
		                            <span class="field">
		                            	<%
		                            		switch(obj.getPlace()){
		                            			case 1:
		                            			%>
		                            			Home Page
		                            			<%
		                            			break;
		                            			case 2:
			                            			%>
			                            			Detail Page
			                            			<%
			                            			break;
		                            			case 3:
			                            			%>
			                            			Newest Page
			                            			<%
			                            			break;
		                            			case 4:
			                            			%>
			                            			Playlist Detail Page
			                            			<%
			                            			break;
		                            			case 5:
			                            			%>
			                            			Channel Detail Page
			                            			<%
			                            			break;
		                            			case 6:
			                            			%>
			                            			Search Result Page
			                            			<%
			                            			break;
		                            			case 7:
			                            			%>
			                            			All Playlist Page
			                            			<%
			                            			break;
		                            		} 		                            	
		                            	%>	                            	
		                            </span>		
		                            <input type="hidden" name="place" value="<%=obj.getPlace() %>">                               		                           
		                        </p>
		                        <p>
		                        	<label>Position : </label>
		                            <span class="field">
		                            	<%=obj.getPosition() %>                         	
		                            </span>		
		                            <input type="hidden" name="position" value="<%=obj.getPosition() %>">                                       		                           
		                        </p>              			                                                                                       
		                        <p id="adsenseContent">
		                        	<label>Content : </label>
		                            <span class="field">
		                            	<textarea cols="80" rows="5" class="longinput" name="content"><%=obj.getContent()%></textarea>		                            			                           
									</span>
									<small class="desc">Small description.</small>
		                        </p>   
		                        <p id="advertisingTitle">
		                        	<label>Title</label>
		                            <span class="field">
		                            	<input type="text" name="title" class="smallinput" value="<%=obj.getTitle()%>"/>
		                            	<% if (check.get("title") != null) { %>
											<label for="title" class="error"><%=check.get("title") %></label>
										<% } %>
		                            </span>		                            		                           
		                        </p> 
		                        <p id="advertisingLink">
		                        	<label>Link</label>
		                            <span class="field">
		                            	<input type="text" name="link" class="smallinput" value="<%=obj.getLink()%>"/>
		                            	<% if (check.get("link") != null) { %>
											<label for="link" class="error"><%=check.get("link") %></label>
										<% } %>
		                            </span>		                            		                           
		                        </p> 
		                        <p id="advertisingImage">
		                        	<label>Image</label>
		                            <span class="field">
		                            	<input type="file" name="image" class="smallinput">
		                            	<% if (check.get("image") != null) { %>
											<label for="image" class="error"><%=check.get("image") %></label>
										<% } %>
										<br/><br/>
										<%
				                           try{
			                            		String imgSrc = imagesService.getServingUrl(blobKey);
				                           %>
				                            		<img src="<%=imgSrc %>=s250" alt="" style="max-width: 250px; max-height: 150px"/>
				                           <%	
				                            }catch(Exception e){
				                            		
				                            }
				                          %>	   
		                            </span> 
		                        </p>  		                                         		                                                                                                                                                                                     		             
		                        <p class="stdformbutton">
		                        	<button class="submit radius2" id="btnSubmit">Submit</button>
		                            <input type="reset" class="reset radius2" value="Reset" />		                            		                           
		                        </p>                                                
                    		</form>             
	                    <br /><br />	                    
	                </div><!--content-->	                
	            </div><!--maincontentinner-->
				<jsp:include page="/admin/elements/bottom.jsp"></jsp:include>                    	           	
	        </div><!--maincontent-->	                        
	     	</div><!--mainwrapperinner-->
	    </div><!--mainwrapper-->
		<!-- END OF MAIN CONTENT -->    
	</body>
</html>
